home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / PowerPlant / LProgressIndicator & Friends / LProgressDialog / LProgressDialog.cp next >
Encoding:
Text File  |  1996-04-20  |  2.6 KB  |  142 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        LProgressDialog.cp
  3.  
  4.     Contains:    Progress bar dialog for PowerPlant.
  5.                 An LProgressIndicatorProxy subclass.
  6.                 
  7.     Version:    2.1
  8.  
  9.     Author:        Chris K. Thomas, ckt@best.com
  10.     
  11.     Copyright:    ©1996 Chris K. Thomas.  All Rights Reserved.
  12. */
  13.  
  14. //
  15. // includes
  16. //
  17.  
  18. #include <UReanimator.h>
  19. #include <LDialogBox.h>
  20. #include <LCaption.h>
  21.  
  22. #include "LThermometerPane.h"
  23. #include "LProgressDialog.h"
  24.  
  25. //
  26. // const
  27. //
  28.  
  29. const UInt16    kProgressDialogID = 1024;    // id of our ‘PPob’
  30.  
  31. const PaneIDT    kFirstCaptionID = 'cap1';        // “Now doing something”
  32. const PaneIDT    kSecondCaptionID = 'cap2';        // “File "martha washington"”
  33. const PaneIDT    kThirdCaptionID = 'capO';        // “40 of 300”
  34. const PaneIDT    kThermometerPaneID = 'prog';    // the star attraction
  35.  
  36. //
  37. // • Construct
  38. //
  39. LProgressDialog::LProgressDialog(Str255 inActivity, LCommander *inSuperCommander)
  40. {
  41.     //
  42.     // setup command chain
  43.     //
  44.     
  45.     LCommander::SetDefaultCommander(inSuperCommander);
  46.     
  47.     //
  48.     // load our dialogbox
  49.     //
  50.     
  51.     mDialog = reinterpret_cast<LDialogBox *>(UReanimator::ReadObjects('PPob', kProgressDialogID));
  52.     ThrowIfNULL_(mDialog);
  53.     
  54.     mDialog->SetSuperCommander(this);
  55.     LCommander::SwitchTarget(mDialog);
  56.     
  57.     mDialog->SetDescriptor(inActivity);
  58.     mDialog->FinishCreate();
  59.     
  60.     mStopClicked = false;
  61.     
  62.     //
  63.     // get pointers to all our panes
  64.     //
  65.     
  66.     mCaptionOne = dynamic_cast<LCaption *>(mDialog->FindPaneByID( kFirstCaptionID ));
  67.     mCaptionTwo = dynamic_cast<LCaption *>(mDialog->FindPaneByID( kSecondCaptionID ));
  68.     mCaptionThree = dynamic_cast<LCaption *>(mDialog->FindPaneByID( kThirdCaptionID ));
  69.     
  70.     mProgressBar = dynamic_cast<LThermometerPane *>(mDialog->FindPaneByID( kThermometerPaneID ));
  71.     
  72.     Assert_(mCaptionOne);
  73.     Assert_(mCaptionTwo);
  74.     Assert_(mCaptionThree);
  75.     Assert_(mProgressBar);
  76.     
  77.     //
  78.     // setup sundry state
  79.     //
  80.     
  81.     SetProxyTarget(mProgressBar);
  82.     
  83.     mCaptionOne->Draw(NULL);
  84. //    mDialog->Draw(NULL);
  85. }
  86.  
  87. LProgressDialog::~LProgressDialog()
  88. {
  89.     if(mDialog)
  90.         delete mDialog;
  91. }
  92.  
  93. //
  94. // • Caption accessors
  95. //
  96. void
  97. LProgressDialog::SetActionDescriptor(Str255 inAction)
  98. {
  99.     mCaptionOne->SetDescriptor(inAction);
  100. }
  101.  
  102. void
  103. LProgressDialog::SetStepDescriptor(Str255 inAction)
  104. {
  105.     mCaptionTwo->SetDescriptor(inAction);
  106. }
  107.  
  108. void
  109. LProgressDialog::SetCountDescriptor(Str255 inAction)
  110. {
  111.     mCaptionThree->SetDescriptor(inAction);
  112. }
  113.  
  114.  
  115. //
  116. // • Command handling (listening for Stop button)
  117. //
  118. Boolean
  119. LProgressDialog::ObeyCommand(
  120.     CommandT    inCommand,
  121.     void        *ioParam )
  122. {
  123.     Boolean    cmdHandled = true;
  124.  
  125.     switch ( inCommand )
  126.     {
  127.         case -1:
  128.             SetStopClicked(true);
  129.             break;
  130.             
  131.         default:
  132.         {
  133.             // Call inherited.
  134.             cmdHandled = LCommander::ObeyCommand( inCommand, ioParam );
  135.         }
  136.         break;
  137.  
  138.     }
  139.  
  140.     return cmdHandled;
  141. }
  142.